$(function () {
    console.log("get detail in ");
    getProductList(type);
    
    
});

function toProductionDetailPage(id){
    var productDetailPageUrl=basePath+"res/xsgpage.html?access_token="+access_token+"&pid=";
    window.location.href=productDetailPageUrl+id;
}

//ajax获取商品详情
function getProductList(type){
    //type:3限时购
    $.ajax({
        url:"/yangcangclub/v1/merchandise/list/show?access_token="+GetUrl("access_token")+"&type="+type+"&orderSort=0&pageSize=30",
        type:'GET',
        dataType:"json",
        success:function(data){
            if(data.code == 1000){
                var data2=data.data;
                data=data.data.list;
                if(data==undefined||data.length==0){return;}
                var html=""
                for(var i=0;i<data.length;i++){
                    html+='<li><div class="txt" onclick="toProductionDetailPage('+data[i].id+');"><div class="t-left"><div class="cont-img">'+
                    '<a href="javascript:void(0);"><img src="'+data[i].bannerUrl+'" ></a></div></div>'+
                    '<div class="t-right"><div class="cont-tit "><div class="h3">'+
                    '<p>'+data[i].name+'</p></div>'+
                    '<p><span class="hour">限时价</span><span class="Price">￥'+data[i].unitPrice+'</span>' +
                        (data[i].showUnitPrice==0?"":
                        '<span class="yprice">原价<s>￥'+data[i].showUnitPrice+'</s></span>') +
                        '</p>'+
                    '<button class="btn"><p>马上抢</p></button></div></div></div></li>';
                }
                $(".ullist").html(html);
                
                // 计算时间
                var now=new Date(data2.now.replace(/-/g,"/"));
                var start=new Date(data2.list[0].startTime.replace(/-/g,"/"));
                var end=new Date(data2.list[0].endTime.replace(/-/g,"/"));
                var stat=data2.sellStatue;//1为可以卖，2为时间未到
                if(stat==2){
                    t=start.getTime()-now.getTime();
                    $(".btn").html("<p>敬请期待</p>");
                }else{
                    t=end.getTime()-now.getTime();
                }
                
            }else{
                layer.open({content: data.msg, skin: 'msg', time: 2});
            }
        },
        error:function(data){
            layer.open({content: '请求失败，请刷新再试', skin: 'msg', time: 2});
        }
    });
    
}


